﻿Namespace ControlLibrary
    ''' <summary>Used to handle the print settings for the standard dbiSchedule Control.</summary>
    Public Class dbiSchedulePrintSettings
        Private l_LandscapeRequired As Boolean = False

        ''' <summary>Determines if the report must be printed in landscape mode.</summary>
        ''' <remarks>In order to preserve formatting and column integrity this value
        ''' will return true if the extra width is required.</remarks>
        Public Property LandscapeRequired() As Boolean
            Get
                Return l_LandscapeRequired
            End Get
            Set(ByVal value As Boolean)
                l_LandscapeRequired = value

                If value Then
                    Me.CheckBoxPrintLandscape.Checked = True
                    Me.CheckBoxPrintLandscape.Enabled = False
                End If
            End Set
        End Property

        ''' <summary>
        ''' Loads the dbiSchedule current settings as well as a predefined PrinterSettings.
        ''' </summary>
        ''' <param name="curSchedule">The dbiSchedule to get the settings from.</param>
        ''' <param name="curPrinterSettings">A system.drawing.printing.printersettings object to set defaults from.</param>
        ''' <remarks></remarks>
        Public Sub LoadSettingsFromSchedule(ByRef curSchedule As Dbi.WinControl.Schedule.dbiSchedule, ByRef curPrinterSettings As System.Drawing.Printing.PrinterSettings)

            Me.TextBoxTitle.Text = curSchedule.PrintTitle
            Me.TextBoxSubTitle.Text = curSchedule.PrintSubTitle
            Me.TextBoxPageText.Text = curSchedule.PrintPageText

            Me.DbiLabelFont.Font = curSchedule.PrintFont

            If LandscapeRequired = False Then
                Me.CheckBoxPrintLandscape.Checked = curPrinterSettings.DefaultPageSettings.Landscape
            End If
            Me.CheckBoxPrintColor.Checked = curPrinterSettings.DefaultPageSettings.Color

            Me.DbiLabelFont.Font = curSchedule.PrintFont

            Me.ComboBoxFooterAlign.DataSource = System.Enum.GetValues(GetType(System.Drawing.ContentAlignment))
            Me.ComboBoxFooterAlign.SelectedItem = curSchedule.PrintFooterAlign

            Me.ComboBoxPageTitleAlign.DataSource = System.Enum.GetValues(GetType(System.Drawing.ContentAlignment))
            Me.ComboBoxPageTitleAlign.SelectedItem = curSchedule.PrintTitleAlign

            Me.ComboBoxReportType.DataSource = System.Enum.GetValues(GetType(Dbi.WinControl.enumPrintReportType))
            Me.ComboBoxReportType.SelectedItem = curSchedule.PrintReportType

            Me.NumericUpDownMarginBottom.Value = curPrinterSettings.DefaultPageSettings.Margins.Bottom
            Me.NumericUpDownMarginLeft.Value = curPrinterSettings.DefaultPageSettings.Margins.Left
            Me.NumericUpDownMarginRight.Value = curPrinterSettings.DefaultPageSettings.Margins.Right
            Me.NumericUpDownMarginTop.Value = curPrinterSettings.DefaultPageSettings.Margins.Top

            Me.ButtonPrintHeaderBackColor.BackColor = curSchedule.PrintHeaderBackColor
            Me.ButtonPrintHeaderForeColor.BackColor = curSchedule.PrintHeaderForeColor

            Me.ButtonPrintItemBackColor.BackColor = curSchedule.PrintItemBackColor
            Me.ButtonPrintItemForeColor.BackColor = curSchedule.PrintItemForeColor

            Me.ButtonPrintTitleBackColor.BackColor = curSchedule.PrintTitleBackColor
            Me.ButtonPrintTitleForeColor.BackColor = curSchedule.PrintTitleForeColor


            Me.CheckBoxPrintPageControl.Checked = Not (curSchedule.PrintPageControl)

            Me.ComboBoxPrintListFormat.DataSource = System.Enum.GetValues(GetType(Dbi.WinControl.enumPrintListFormat))
            Me.ComboBoxPrintListFormat.SelectedItem = curSchedule.PrintListFormat

            Me.ComboBoxReportType.DataSource = System.Enum.GetValues(GetType(Dbi.WinControl.enumPrintReportType))
            Me.ComboBoxReportType.SelectedItem = curSchedule.PrintReportType

            Me.Refresh()
        End Sub

        ''' <summary>
        ''' Sets the dbiSchedule and PrinterSettings object with the values set in the control.
        ''' </summary>
        ''' <param name="curSchedule">The dbiSchedule to apply the values set herein.</param>
        ''' <param name="curPrinterSettings">The system.drawing.printing.printersettings object to apply the values set herein.</param>
        Public Sub ApplySettingsToSchedule(ByRef curSchedule As Dbi.WinControl.Schedule.dbiSchedule, ByRef curPrinterSettings As System.Drawing.Printing.PrinterSettings)
            curSchedule.PrintTitle = Me.TextBoxTitle.Text
            curSchedule.PrintSubTitle = Me.TextBoxSubTitle.Text
            curSchedule.PrintPageText = Me.TextBoxPageText.Text

            curSchedule.PrintFont = Me.DbiLabelFont.Font


            curPrinterSettings.DefaultPageSettings.Landscape = Me.CheckBoxPrintLandscape.Checked

            curPrinterSettings.DefaultPageSettings.Color = Me.CheckBoxPrintColor.Checked

            curSchedule.PrintFont = Me.DbiLabelFont.Font

            curSchedule.PrintFooterAlign = Me.ComboBoxFooterAlign.SelectedItem

            curSchedule.PrintTitleAlign = Me.ComboBoxPageTitleAlign.SelectedItem

            curSchedule.PrintReportType = Me.ComboBoxReportType.SelectedItem

            curPrinterSettings.DefaultPageSettings.Margins.Bottom = Me.NumericUpDownMarginBottom.Value
            curPrinterSettings.DefaultPageSettings.Margins.Left = Me.NumericUpDownMarginLeft.Value
            curPrinterSettings.DefaultPageSettings.Margins.Right = Me.NumericUpDownMarginRight.Value
            curPrinterSettings.DefaultPageSettings.Margins.Top = Me.NumericUpDownMarginTop.Value

            curSchedule.PrintHeaderBackColor = Me.ButtonPrintHeaderBackColor.BackColor
            curSchedule.PrintHeaderForeColor = Me.ButtonPrintHeaderForeColor.BackColor

            curSchedule.PrintItemBackColor = Me.ButtonPrintItemBackColor.BackColor
            curSchedule.PrintItemForeColor = Me.ButtonPrintItemForeColor.BackColor

            curSchedule.PrintTitleBackColor = Me.ButtonPrintTitleBackColor.BackColor
            curSchedule.PrintTitleForeColor = Me.ButtonPrintTitleForeColor.BackColor

            curSchedule.PrintPageControl = Not (Me.CheckBoxPrintPageControl.Checked)

            curSchedule.PrintListFormat = Me.ComboBoxPrintListFormat.SelectedItem

        End Sub

        ''' <summary>Displays a color dialog if the color button is clicked.</summary>
        Private Sub ButtonColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonPrintItemForeColor.Click, ButtonPrintItemBackColor.Click, ButtonPrintHeaderForeColor.Click, ButtonPrintHeaderBackColor.Click, ButtonPrintTitleForeColor.Click, ButtonPrintTitleBackColor.Click
            ColorDialog1.Color = sender.backcolor
            ColorDialog1.ShowDialog()
            sender.backcolor = ColorDialog1.Color
        End Sub

        ''' <summary>Displays a font dialog if the font label is clicked.</summary>
        Private Sub FontLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DbiLabelFont.Click
            FontDialog1.Font = sender.font
            FontDialog1.ShowDialog()
            sender.font = FontDialog1.Font
        End Sub
    End Class
End Namespace
